package com.ruoyi.web.controller.tuihuo;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tuihuo.domain.Tuihuo;
import com.ruoyi.tuihuo.service.ITuihuoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购货退货Controller
 *
 * @author ruoyi
 * @date 2023-05-23
 */
@Api(tags="购货退货管理")
@RestController
@RequestMapping("/system/tuihuo")
public class TuihuoController extends BaseController
{
    @Autowired
    private ITuihuoService tuihuoService;

    /**
     * 查询购货退货列表
     */
    @ApiOperation("查询购货退货列表")
    @PreAuthorize("@ss.hasPermi('ghgl:ghth:list')")
    @GetMapping("/list")
    public TableDataInfo list(Tuihuo tuihuo)
    {
        startPage();
        List<Tuihuo> list = tuihuoService.selectTuihuoList(tuihuo);
        return getDataTable(list);
    }

    /**
     * 导出购货退货列表
     */
//    @PreAuthorize("@ss.hasPermi('system:tuihuo:export')")
    @Log(title = "购货退货", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Tuihuo tuihuo)
    {
        List<Tuihuo> list = tuihuoService.selectTuihuoList(tuihuo);
        ExcelUtil<Tuihuo> util = new ExcelUtil<Tuihuo>(Tuihuo.class);
        util.exportExcel(response, list, "购货退货数据");
    }

    /**
     * 获取购货退货详细信息
     */
    @ApiOperation("获取购货退货详细")
//    @PreAuthorize("@ss.hasPermi('system:tuihuo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tuihuoService.selectTuihuoById(id));
    }

    /**
     * 新增购货退货
     */
    @ApiOperation("新增购货退货")
//    @PreAuthorize("@ss.hasPermi('system:tuihuo:add')")
    @Log(title = "购货退货", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tuihuo tuihuo)
    {
        tuihuo.setTuihuoJingshouren(getLoginUser().getUser().getNickName());
        return toAjax(tuihuoService.insertTuihuo(tuihuo));
    }

    /**
     * 修改购货退货
     */
    @ApiOperation("修改购货退货")
//    @PreAuthorize("@ss.hasPermi('system:tuihuo:edit')")
    @Log(title = "购货退货", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tuihuo tuihuo)
    {
        return toAjax(tuihuoService.updateTuihuo(tuihuo));
    }

    /**
     * 删除购货退货
     */
    @ApiOperation("删除购货退货")
//    @PreAuthorize("@ss.hasPermi('system:tuihuo:remove')")
    @Log(title = "购货退货", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tuihuoService.deleteTuihuoByIds(ids));
    }
}
